#文章管理的model
config = require('../config')
Schema = config.Schema
mongoose = config.mongoose
S = require("string")
async = require('async')
Dict = require('./dict').Dict

ArticleSchema = new Schema({
  title :
    type : String
    required : true
  type :
    type : String
    required :true
  type_name : String
  type_path : String
  code : String
  author : String
  content : String
  content_strip : String
  summary : String
  source_web : String
  source_url : String
  source_from : String
  source_date : Date
  create_date : Date
  create_by : String
  priority  : Number
  updated_at : Date
  status : String
  begin_date : Number
  end_date : Number
  sorder : Number
  target : String
  _url : String
  image_page_title_id : String
  doc_id : Number
  file_list : [
    file_id:String
    file_name:String
    file_size:Number
    upload_date : Date
  ]
  ex1 : String
  ex2 : String
  ex3 : String
  ex4 : String
})


ArticleSchema.methods.add = (req,type_name,cb) ->
  content = req.param("content")
  this.summary = req.param("summary")
  this.title = req.param('title')
  this.target = req.param('target')
  this._url = req.param('_url')
  this.begin_date = req.param('begin_date')
  this.end_date = req.param('end_date')
  this.sorder = req.param('sorder')
  this.code = req.param('code')
  this.type = req.param('type') || "none"
  this.type_name = type_name
  this.type_path = req.param("type_path")
  this.author = req.param('author')
  this.content = req.param('content')
  this.priority = req.param('priority')  || 0
  this.source_web = req.param('source_web')
  this.source_url = req.param('source_url')
  this.source_date = req.param('source_date')
  this.source_from = req.param('source_from')
  this.create_date = new Date
  this.create_by = req.param('create_by')
  this.updated_at = new Date
  this.status = req.param('status') || '0'
  this.priority = req.param('priority') || 0
  this.content_strip = S(content).stripTags().s if content
  this.file_list = []
  this.image_page_title_id = req.param('image_page_title_id')
  this.ex1 = req.param("ex1") || ''
  this.ex2 = req.param("ex2") || ''
  this.ex3 = req.param("ex3") || ''
  this.ex4 = req.param("ex4") || ''
  this.save cb
  #console.log '555555'
  #this.save cb
    
ArticleSchema.methods.addByParam = (param,cb) ->
  this.title = param.title
  this.target = param.target
  this._url = param._url
  this.begin_date = param.begin_date
  this.end_date = param.end_date
  this.sorder = param.sorder
  this.code = param.code
  this.type = param.type
  this.author = param.author
  this.content = param.content
  this.priority =  param.priority  || 0
  this.source_from = param.source_from
  this.source_date = param.source_date
  this.source_url = param.source_url
  this.source_web = param.source_web
  this.create_date = new Date
  this.create_by = param.create_by
  this.updated_at = new Date
  this.status = param.status || '0'
  this.priority = param.priority || 0
  this.file_list = []
  this.image_page_title_id = param.image_page_title_id
  this.ex1 = param.ex1 || ''
  this.ex2 = param.ex2 || ''
  this.ex3 = param.ex3 || ''
  this.ex4 = param.ex4 || ''
  this.doc_id = param.doc_id || 0
  this.save cb
  

#exports.PurIntent = modeldb.model 'PurIntent', PurIntentSchema
exports.Article = mongoose.model 'Article', ArticleSchema